00001 // ========================================================== 00002 // FreeImagePlus 3 00003 // 00004 // Design and implementation by 00005 // - Hervé Drolon (drolon@infonie.fr) 00006 // 00007 // This file is part of FreeImage 3 00008 // 00009 // COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY 00010 // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES 00011 // THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE 00012 // OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED 00013 // CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT 00014 // THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY 00015 // SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL 00016 // PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER 00017 // THIS DISCLAIMER. 00018 // 00019 // Use at your own risk! 00020 // ========================================================== 00021 00022 #ifndef FREEIMAGEPLUS_H 00023 #define FREEIMAGEPLUS_H 00024 00025 #ifdef _WIN32 00026 #include <windows.h> 00027 #endif // _WIN32 00028 #include "FreeImage.h" 00029 00030 00031 // Compiler options --------------------------------------------------------- 00032 00033 #if defined(FREEIMAGE_LIB) 00034 #define FIP_API 00035 #define FIP_CALLCONV 00036 #else 00037 #if defined(_WIN32) || defined(__WIN32__) 00038 #define WIN32_LEAN_AND_MEAN 00039 #define FIP_CALLCONV __stdcall 00040 // The following ifdef block is the standard way of creating macros which make exporting 00041 // from a DLL simpler. All files within this DLL are compiled with the FIP_EXPORTS 00042 // symbol defined on the command line. this symbol should not be defined on any project 00043 // that uses this DLL. This way any other project whose source files include this file see 00044 // FIP_API functions as being imported from a DLL, wheras this DLL sees symbols 00045 // defined with this macro as being exported. 00046 #ifdef FIP_EXPORTS 00047 #define FIP_API __declspec(dllexport) 00048 #else 00049 #define FIP_API __declspec(dllimport) 00050 #endif // FIP_EXPORTS 00051 #else 00052 // try the gcc visibility support (see http://gcc.gnu.org/wiki/Visibility) 00053 #if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) 00054 #ifndef GCC_HASCLASSVISIBILITY 00055 #define GCC_HASCLASSVISIBILITY 00056 #endif 00057 #endif 00058 #define FIP_CALLCONV 00059 #if defined(GCC_HASCLASSVISIBILITY) 00060 #define FIP_API __attribute__ ((visibility("default"))) 00061 #else 00062 #define FIP_API 00063 #endif 00064 #endif // WIN32 / !WIN32 00065 #endif // FREEIMAGE_LIB 00066 00068 00069 // ---------------------------------------------------------- 00070 00076 class FIP_API fipObject 00077 { 00078 public: 00080 virtual ~fipObject(){}; 00081 00084 00085 virtual BOOL isValid() const = 0; 00087 }; 00088 00089 // ---------------------------------------------------------- 00090 00091 class fipMemoryIO; 00092 class fipMultiPage; 00093 class fipTag; 00094 00103 class FIP_API fipImage : public fipObject 00104 { 00105 protected: 00107 FIBITMAP *_dib; 00109 FREE_IMAGE_FORMAT _fif; 00111 mutable BOOL _bHasChanged; 00112 00113 public: 00114 friend class fipMultiPage; 00115 00116 public: 00117 00124 fipImage(FREE_IMAGE_TYPE image_type = FIT_BITMAP, unsigned width = 0, unsigned height = 0, unsigned bpp = 0); 00126 virtual ~fipImage(); 00131 BOOL setSize(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height, unsigned bpp, unsigned red_mask = 0, unsigned green_mask = 0, unsigned blue_mask = 0); 00133 virtual void clear(); 00135 00142 fipImage(const fipImage& src); 00147 fipImage& operator=(const fipImage& src); 00153 fipImage& operator=(FIBITMAP *dib); 00154 00155 00168 BOOL copySubImage(fipImage& dst, int left, int top, int right, int bottom) const; 00169 00183 BOOL pasteSubImage(fipImage& src, int left, int top, int alpha = 256); 00184 00195 BOOL crop(int left, int top, int right, int bottom); 00196 00198 00208 static FREE_IMAGE_FORMAT identifyFIF(const char* lpszPathName); 00209 00214 static FREE_IMAGE_FORMAT identifyFIFU(const wchar_t* lpszPathName); 00215 00223 static FREE_IMAGE_FORMAT identifyFIFFromHandle(FreeImageIO *io, fi_handle handle); 00224 00231 static FREE_IMAGE_FORMAT identifyFIFFromMemory(FIMEMORY *hmem); 00232 00234 00235 00247 BOOL load(const char* lpszPathName, int flag = 0); 00248 00253 BOOL loadU(const wchar_t* lpszPathName, int flag = 0); 00254 00263 BOOL loadFromHandle(FreeImageIO *io, fi_handle handle, int flag = 0); 00264 00272 BOOL loadFromMemory(fipMemoryIO& memIO, int flag = 0); 00273 00281 BOOL save(const char* lpszPathName, int flag = 0) const; 00282 00287 BOOL saveU(const wchar_t* lpszPathName, int flag = 0) const; 00288 00298 BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flag = 0) const; 00299 00308 BOOL saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flag = 0) const; 00309 00311 00316 00321 FREE_IMAGE_TYPE getImageType() const; 00322 00327 unsigned getWidth() const; 00328 00333 unsigned getHeight() const; 00334 00339 unsigned getScanWidth() const; 00340 00353 operator FIBITMAP*() { 00354 return _dib; 00355 } 00356 00358 BOOL isValid() const; 00359 00364 BITMAPINFO* getInfo() const; 00365 00370 BITMAPINFOHEADER* getInfoHeader() const; 00371 00377 LONG getImageSize() const; 00378 00384 unsigned getBitsPerPixel() const; 00385 00391 unsigned getLine() const; 00392 00397 double getHorizontalResolution() const; 00398 00403 double getVerticalResolution() const; 00404 00409 void setHorizontalResolution(double value); 00410 00415 void setVerticalResolution(double value); 00416 00418 00425 RGBQUAD* getPalette() const; 00426 00431 unsigned getPaletteSize() const; 00432 00437 unsigned getColorsUsed() const; 00438 00443 FREE_IMAGE_COLOR_TYPE getColorType() const; 00444 00449 BOOL isGrayscale() const; 00451 00454 00460 BOOL getThumbnail(fipImage& image) const; 00461 00467 BOOL setThumbnail(const fipImage& image); 00468 00474 BOOL hasThumbnail() const; 00475 00481 BOOL clearThumbnail(); 00482 00484 00487 00496 BYTE* accessPixels() const; 00497 00503 BYTE* getScanLine(unsigned scanline) const; 00504 00513 BOOL getPixelIndex(unsigned x, unsigned y, BYTE *value) const; 00514 00523 BOOL getPixelColor(unsigned x, unsigned y, RGBQUAD *value) const; 00524 00533 BOOL setPixelIndex(unsigned x, unsigned y, BYTE *value); 00534 00543 BOOL setPixelColor(unsigned x, unsigned y, RGBQUAD *value); 00544 00546 00558 BOOL convertToType(FREE_IMAGE_TYPE image_type, BOOL scale_linear = TRUE); 00559 00566 BOOL threshold(BYTE T); 00567 00574 BOOL dither(FREE_IMAGE_DITHER algorithm); 00575 00581 BOOL convertTo4Bits(); 00582 00588 BOOL convertTo8Bits(); 00589 00596 BOOL convertToGrayscale(); 00597 00605 BOOL colorQuantize(FREE_IMAGE_QUANTIZE algorithm); 00606 00612 BOOL convertTo16Bits555(); 00613 00619 BOOL convertTo16Bits565(); 00620 00626 BOOL convertTo24Bits(); 00627 00633 BOOL convertTo32Bits(); 00634 00640 BOOL convertToRGBF(); 00641 00647 BOOL convertToUINT16(); 00648 00659 BOOL toneMapping(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0, double third_param = 1, double fourth_param = 0); 00660 00662 00665 00670 BOOL isTransparent() const; 00671 00677 unsigned getTransparencyCount() const; 00678 00684 BYTE* getTransparencyTable() const; 00685 00690 void setTransparencyTable(BYTE *table, int count); 00691 00696 BOOL hasFileBkColor() const; 00697 00706 BOOL getFileBkColor(RGBQUAD *bkcolor) const; 00707 00716 BOOL setFileBkColor(RGBQUAD *bkcolor); 00718 00727 BOOL getChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel) const; 00728 00736 BOOL setChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel); 00737 00746 BOOL splitChannels(fipImage& RedChannel, fipImage& GreenChannel, fipImage& BlueChannel); 00747 00755 BOOL combineChannels(fipImage& red, fipImage& green, fipImage& blue); 00757 00771 BOOL rotateEx(double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask); 00772 00780 BOOL rotate(double angle, const void *bkcolor = NULL); 00781 00786 BOOL flipHorizontal(); 00787 00792 BOOL flipVertical(); 00794 00802 BOOL invert(); 00803 00817 BOOL adjustCurve(BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel); 00818 00825 BOOL adjustGamma(double gamma); 00826 00834 BOOL adjustBrightness(double percentage); 00835 00843 BOOL adjustContrast(double percentage); 00844 00855 BOOL adjustBrightnessContrastGamma(double brightness, double contrast, double gamma); 00856 00867 BOOL getHistogram(DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel = FICC_BLACK) const; 00869 00872 00881 BOOL rescale(unsigned new_width, unsigned new_height, FREE_IMAGE_FILTER filter); 00882 00890 BOOL makeThumbnail(unsigned max_size, BOOL convert = TRUE); 00892 00902 void setModified(BOOL bStatus = TRUE) { 00903 _bHasChanged = bStatus; 00904 } 00905 00911 BOOL isModified() { 00912 return _bHasChanged; 00913 } 00915 00923 unsigned getMetadataCount(FREE_IMAGE_MDMODEL model) const; 00932 BOOL getMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag) const; 00952 BOOL setMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag); 00954 00955 00956 protected: 00959 BOOL replace(FIBITMAP *new_dib); 00961 00962 }; 00963 00964 // ---------------------------------------------------------- 00965 00977 #ifdef _WIN32 00978 00979 class FIP_API fipWinImage : public fipImage 00980 { 00981 public: 00984 00985 fipWinImage(FREE_IMAGE_TYPE image_type = FIT_BITMAP, unsigned width = 0, unsigned height = 0, unsigned bpp = 0); 00986 00988 virtual ~fipWinImage(); 00989 00991 virtual void clear(); 00992 00994 BOOL isValid() const; 00996 00999 01006 fipWinImage& operator=(const fipImage& src); 01007 01014 fipWinImage& operator=(const fipWinImage& src); 01015 01022 HANDLE copyToHandle() const; 01023 01030 BOOL copyFromHandle(HANDLE hMem); 01031 01036 BOOL copyFromBitmap(HBITMAP hbmp); 01038 01047 BOOL copyToClipboard(HWND hWndNewOwner) const; 01048 01053 BOOL pasteFromClipboard(); 01055 01063 BOOL captureWindow(HWND hWndApplicationWindow, HWND hWndSelectedWindow); 01065 01066 01069 01078 void draw(HDC hDC, RECT& rcDest) const { 01079 drawEx(hDC, rcDest, FALSE, NULL, NULL); 01080 } 01081 01099 void drawEx(HDC hDC, RECT& rcDest, BOOL useFileBkg = FALSE, RGBQUAD *appBkColor = NULL, FIBITMAP *bg = NULL) const; 01100 01111 void setToneMappingOperator(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0, double third_param = 1, double fourth_param = 0); 01112 01122 void getToneMappingOperator(FREE_IMAGE_TMO *tmo, double *first_param, double *second_param, double *third_param, double *fourth_param) const; 01123 01125 01126 protected: 01128 mutable FIBITMAP *_display_dib; 01130 mutable BOOL _bDeleteMe; 01132 FREE_IMAGE_TMO _tmo; 01134 double _tmo_param_1; 01136 double _tmo_param_2; 01138 double _tmo_param_3; 01140 double _tmo_param_4; 01141 }; 01142 01143 #endif // _WIN32 01144 01145 // ---------------------------------------------------------- 01146 01153 class FIP_API fipMemoryIO : public fipObject 01154 { 01155 protected: 01157 FIMEMORY *_hmem; 01158 01159 public : 01169 fipMemoryIO(BYTE *data = NULL, DWORD size_in_bytes = 0); 01170 01175 virtual ~fipMemoryIO(); 01176 01181 void close(); 01182 01185 BOOL isValid() const; 01186 01190 FREE_IMAGE_FORMAT getFileType() const; 01191 01196 operator FIMEMORY*() { 01197 return _hmem; 01198 } 01199 01209 FIBITMAP* load(FREE_IMAGE_FORMAT fif, int flags = 0) const; 01217 FIMULTIBITMAP* loadMultiPage(FREE_IMAGE_FORMAT fif, int flags = 0) const; 01226 BOOL save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, int flags = 0); 01235 BOOL saveMultiPage(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, int flags = 0); 01244 unsigned read(void *buffer, unsigned size, unsigned count) const; 01253 unsigned write(const void *buffer, unsigned size, unsigned count); 01258 long tell() const; 01263 BOOL seek(long offset, int origin); 01270 BOOL acquire(BYTE **data, DWORD *size_in_bytes); 01272 01273 private: 01275 fipMemoryIO(const fipMemoryIO& src); 01277 fipMemoryIO& operator=(const fipMemoryIO& src); 01278 01279 }; 01280 01281 // ---------------------------------------------------------- 01282 01288 class FIP_API fipMultiPage : public fipObject 01289 { 01290 protected: 01292 FIMULTIBITMAP *_mpage; 01294 BOOL _bMemoryCache; 01295 01296 public: 01301 fipMultiPage(BOOL keep_cache_in_memory = FALSE); 01302 01307 virtual ~fipMultiPage(); 01308 01310 BOOL isValid() const; 01311 01316 operator FIMULTIBITMAP*() { 01317 return _mpage; 01318 } 01319 01329 BOOL open(const char* lpszPathName, BOOL create_new, BOOL read_only, int flags = 0); 01330 01338 BOOL open(fipMemoryIO& memIO, int flags = 0); 01339 01348 BOOL open(FreeImageIO *io, fi_handle handle, int flags = 0); 01349 01356 BOOL close(int flags = 0); 01357 01367 BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags = 0) const; 01368 01377 BOOL saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flags = 0) const; 01378 01383 int getPageCount() const; 01384 01390 void appendPage(fipImage& image); 01391 01398 void insertPage(int page, fipImage& image); 01399 01405 void deletePage(int page); 01406 01414 BOOL movePage(int target, int source); 01415 01433 FIBITMAP* lockPage(int page); 01434 01441 void unlockPage(fipImage& image, BOOL changed); 01442 01451 BOOL getLockedPageNumbers(int *pages, int *count) const; 01452 }; 01453 01454 // ---------------------------------------------------------- 01455 01461 class FIP_API fipTag : public fipObject 01462 { 01463 protected: 01465 FITAG *_tag; 01466 01467 public: 01474 fipTag(); 01479 virtual ~fipTag(); 01488 BOOL setKeyValue(const char *key, const char *value); 01489 01491 01498 fipTag(const fipTag& tag); 01503 fipTag& operator=(const fipTag& tag); 01509 fipTag& operator=(FITAG *tag); 01511 01517 operator FITAG*() { 01518 return _tag; 01519 } 01520 01522 BOOL isValid() const; 01523 01530 const char *getKey() const; 01535 const char *getDescription() const; 01540 WORD getID() const; 01545 FREE_IMAGE_MDTYPE getType() const; 01550 DWORD getCount() const; 01555 DWORD getLength() const; 01560 const void *getValue() const; 01566 BOOL setKey(const char *key); 01572 BOOL setDescription(const char *description); 01578 BOOL setID(WORD id); 01584 BOOL setType(FREE_IMAGE_MDTYPE type); 01590 BOOL setCount(DWORD count); 01596 BOOL setLength(DWORD length); 01602 BOOL setValue(const void *value); 01603 01605 01611 const char* toString(FREE_IMAGE_MDMODEL model, char *Make = NULL) const; 01612 01613 }; 01614 01641 class FIP_API fipMetadataFind : public fipObject 01642 { 01643 protected: 01645 FIMETADATA *_mdhandle; 01646 01647 public: 01649 BOOL isValid() const; 01650 01652 fipMetadataFind(); 01657 virtual ~fipMetadataFind(); 01667 BOOL findFirstMetadata(FREE_IMAGE_MDMODEL model, fipImage& image, fipTag& tag); 01675 BOOL findNextMetadata(fipTag& tag); 01676 01677 }; 01678 01679 #endif // FREEIMAGEPLUS_H
